<?php
namespace App\Api\Models;

use App\Api\Services\JsonService;
use Illuminate\Database\Eloquent\Model;

class CmcBankCard extends Model
{
    //选择数据库
    protected $table = 'cmc_bank_card';

    /**
     * 查询用户绑定银行卡
     * @param $memberId 用户id
     * @param $allowField 查询字段
     * @return mixed
     */
    public static function getBankCard($memberId,$allowField)
    {
        return self::where('member_id',$memberId)->select($allowField)->get()->toArray();
    }

    /**
     * 绑定银行卡
     * @param $params 所需参数
     */
    public static function addBankCard($params)
    {
        $bankCardData = self::where('bank_card_number',$params['bank_card_number'])->first();

        if($bankCardData){
            return JsonService::fail('本卡已被绑定','',400);
        }

        $bankCardRes = self::insert($params);

        if($bankCardRes){
            return JsonService::success('绑定银行卡成功');
        }
        return JsonService::fail('银行卡绑定失败,请检查您的网络','',1003);
    }
}